<?php

namespace App\Http\Requests\App\Store;

use App\Http\Middleware\AppAuth;
use App\Http\Requests\ApiRequest;
use App\Models\Panx\SkinDetector;
use App\Models\Store\HmSkinRecord;
use App\Models\Store\WaxSkinRecord;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string skin_detector_id
 * @property string $store_admin_id
 * @property int skin_record_id
 * @property int itemsid
 * @property string itemsname
 * @property string value
 * @property string type
 * @property int levelsort
 * @property int wechat_user_id
 * @property int|null no_send_skin_info
 * @property string origin_img
 * @property string analyse_img
 *
 * @property double dark_circle
 * @property double stain
 * @property double acne
 * @property double health
 *
 * @property int position
 * @property double flex
 * @property double oil
 * @property double water
 * @property int age
 */
class SkinRecordStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $default_rule = [
            'skin_detector_id'  => ['required', Rule::in(SkinDetector::validatedIds())],
            'wechat_user_id'    => 'required|int|min:1',
            'skin_record_id'    => 'nullable|int|min:1',
            'no_send_skin_info' => 'sometimes|required|int'
        ];

        $skin_detector_id = $this->skin_detector_id;
        switch($skin_detector_id)
        {
            case SkinDetector::ID_WAX:
                $append_rule = [
                    'itemsid'     => ['required', 'int', Rule::in(WaxSkinRecord::ITEMSID_ALL)],
                    'itemsname'   => 'nullable|string',
                    'value'       => 'required|numeric|between:0,100',
                    'type'        => 'nullable',
                    'levelsort'   => 'required',
                    'origin_img'  => 'nullable|file|max:2048',
                    'analyse_img' => 'nullable|file|max:2048',
                ];
                break;
            case SkinDetector::ID_CAMERA:
                $append_rule = [
                    'dark_circle' => 'required',
                    'stain'       => 'required',
                    'acne'        => 'required',
                    'health'      => 'required',
                ];
                break;
            case SkinDetector::ID_HM:
                $append_rule = [
                    'position' => ['required', 'int' , Rule::in(HmSkinRecord::ALL_POSITIONS)],
                    'flex'     => ['required', 'numeric', 'between:0,10'],
                    'oil'      => ['required', 'numeric', 'between:0,50'],
                    'water'    => ['required', 'numeric', 'between:0,100'],
                    'age'      => ['required', 'int', 'between:0,100'],
                ];
                break;
            default:
                $append_rule = [];
        }

        return $default_rule + $append_rule;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'skin_detector_id.*' => '肤质检测的类型必须是1,2或3',
//            'wechat_user_id.*'   => '微信用户的编号必须是大于0的数字',
//            'skin_record_id.*'   => '肤质检测记录id必须是大于0的数字',
//
//            'itemsid.*'        => 'wax检测项目的id必须是数字',
//            'itemsname.*'      => 'wax检测项目名称必须是字符串',
//            'value.*'          => 'wax检测的值必须填写',
//            'type.*'           => 'wax检测类型常量必须填写',
//            'levelsort.*'      => 'wax检测水平阶段值必须填写',
//            'origin_img.*'     => 'wax检测摄像拍照原图必须是小于2M的图片',
//            'analyse_img.*'    => 'wax检测分析结果合成图必须是小于2M的图片',
//
//            'dark_circle.*'    => 'cam检测黑眼圈值必须填写',
//            'stain.*'          => 'cam检测色斑值必须填写',
//            'acne.*'           => 'cam检测粉刺值必须填写',
//            'health.*'         => 'cam检测健康度必须填写',
//
//            'position.*'       => 'hm检测的位置必须填写',
//            'flex.*'           => 'hm检测弹性值必须填写',
//            'oil.*'            => 'hm检测油分值必须填写',
//            'water.*'          => 'hm检测水分值必须填写',
//            'age.*'            => 'hm检测年龄值必须填写'
//        ];
//    }
}
